package com.antoco.operation.bigscreen.third.jwt;

import com.antoco.operation.bigscreen.model.entity.User;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.util.Collection;

/**
 * @author guozy
 * @date 2018-11-23
 */
@Getter
@AllArgsConstructor
public class JwtUser implements UserDetails {

  private static final long serialVersionUID = -7902680224827400883L;

  @JsonIgnore
  private final String id;

  private final String username;

  @JsonIgnore
  private final String password;

  @JsonIgnore
  private final Collection<? extends GrantedAuthority> authorities;

  public JwtUser(User user) {
    id = user.getId();
    // username = user.getUserName();
    username = user.getCode();
    password = user.getPassword();
    authorities = null;
  }

  @JsonIgnore
  @Override
  public boolean isAccountNonExpired() {
      return true;
  }

  @JsonIgnore
  @Override
  public boolean isAccountNonLocked() {
      return true;
  }

  @JsonIgnore
  @Override
  public boolean isCredentialsNonExpired() {
      return true;
  }

  @Override
  public boolean isEnabled() {
    return true;
  }

  @Override
  public Collection<? extends GrantedAuthority> getAuthorities() {
    return null;
  }
}
